﻿namespace WriteForFighting.Game.View.Control
{
    class ControlManager
    {
        private ControlBase[] controls;
        private int usedArrayHeader;

        public ControlManager(int maxHoldableControl)
        {
            controls = new ControlBase[maxHoldableControl];
        }

        public void UpdateControls()
        {
            for (int i = 0; i < controls.Length; ++i)
            {
                if (controls[i] != null)
                {
                    controls[i].Update();
                }
            }
        }

        public void DrawControls()
        {
            foreach (ControlBase c in controls)
            {
                if (c != null)
                {
                    c.Draw();
                }
            }
        }

        public void AddControl(ControlBase entity)
        {
            for (int i = 0; i < 2; ++i)
            {
                for (int j = usedArrayHeader + 1; j < controls.Length; ++j)
                {
                    if (controls[j] == null)
                    {
                        controls[j] = entity;
                        usedArrayHeader = j;
                        return;
                    }
                }

                usedArrayHeader = -1;
            }
        }
    }
}
